﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using HRS_Service.BookingWCF;
using BusinessComponents;
using DataAccessLayer;

namespace HRS_Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "BookingService" in code, svc and config file together.
    public class BookingService : IBookingService
    {


        public List<HRS_Service.BookingWCF.RoomType> FindAvailableRoomType(DateTime StartDate, DateTime EndDate, Int32 NoOfGuest)
        {
            List<HRS_Service.BookingWCF.RoomType> rtList = new List<BookingWCF.RoomType>();
            BusinessComponentsFacade facade = new BusinessComponentsFacade();
            List<DataAccessLayer.RoomType> roomTypeList = facade.FindAvailableRoomType(StartDate, EndDate, NoOfGuest);
            foreach (DataAccessLayer.RoomType rt in roomTypeList)
            {
                rtList.Add(Utilities.convert(rt));
            }
            return rtList;
        }


   
        public String MakeReservation(BookingWCF.Booking b, List<BookingWCF.Guest> guestList)
        {
            BusinessComponentsFacade facade = new BusinessComponentsFacade();
            try
            {
                DataAccessLayer.Booking booking = Utilities.convert(b);
                List<DataAccessLayer.Guest> guests = new List<DataAccessLayer.Guest>();
                foreach (BookingWCF.Guest guest in guestList)
                {
                    DataAccessLayer.Guest g = Utilities.convert(guest);
                    booking.Guests.Add(g);

                }
                return facade.MakeReservation(booking);
            }
            catch (Exception e)
            {

                return "";
            }


        }


        public BookingWCF.Booking FindBooking(string bookingNo)
        {
            BusinessComponentsFacade facade = new BusinessComponentsFacade();
            DataAccessLayer.Booking b = facade.FindByBookingNumber(bookingNo);
             return  Utilities.convert(b);


        }

        public List<BookingWCF.Booking> FindBookingsByGuestId(int guestId)
        {
            BusinessComponentsFacade facade = new BusinessComponentsFacade();
            List<BookingWCF.Booking> g = Utilities.convert(facade.FindBookingByGuestId(guestId));
            return g;
        }

        public BookingWCF.Guest FindGuestByID(int guestId)
        {
            BusinessComponentsFacade facade = new BusinessComponentsFacade();
            return Utilities.convert(facade.FindGuestByID(guestId));
        }

        public void AddGuest(BookingWCF.Guest guest)
        {
            BusinessComponentsFacade facade = new BusinessComponentsFacade();
            facade.AddGuest(Utilities.convert(guest));
        }


        
    }
}